package com.lydia.servlet;

import com.lydia.service.DataSynService;
import lombok.SneakyThrows;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/form-handler")
public class DataSyn extends HttpServlet {

    private final DataSynService dataSynService = new DataSynService();
    @Override
    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
        System.out.println("dataSyn test!!!!");
    }
    @SneakyThrows
    @Override
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

        String[] synType = request.getParameterValues("synType");

        Map<String, Object> param = new HashMap<>(16);
        param.put("fromType", request.getParameter("fromType"));
        param.put("fromUrl", request.getParameter("fromUrl"));
        param.put("fromPort", request.getParameter("fromPort"));
        param.put("fromOracleType", request.getParameter("fromOracleType"));
        param.put("fromDbName", request.getParameter("fromDbName"));
        param.put("fromSchema", request.getParameter("fromSchema"));
        param.put("fromUsername", request.getParameter("fromUsername"));
        param.put("fromPassword", request.getParameter("fromPassword"));
        param.put("toType", request.getParameter("toType"));
        param.put("toUrl", request.getParameter("toUrl"));
        param.put("toPort", request.getParameter("toPort"));
        param.put("toDbName", request.getParameter("toDbName"));
        param.put("toSchema", request.getParameter("toSchema"));
        param.put("toUsername", request.getParameter("toUsername"));
        param.put("toPassword", request.getParameter("toPassword"));
        param.put("synType", Arrays.asList(synType));
        param.put("sysnTables", request.getParameter("sysnTables"));
        param.put("toOracleType", request.getParameter("toOracleType"));
        dataSynService.doSyn(param);

//        response.setContentType("text/plain;charset=UTF-8");
//
//        StringBuilder resultMessage = new StringBuilder("<ul>");
//        response.getWriter().write(resultMessage.toString());
    }
}
